package com.hexiang.mapper;

import java.util.List;
import java.util.Map;

import com.hexiang.domain.User;
import org.apache.ibatis.annotations.*;

@Mapper
public interface UserMapper {

    @Select("SELECT * FROM user WHERE name = #{name}")
    User findByName(@Param("name") String name);

    @Insert("INSERT INTO user(name, age) VALUES(#{name}, #{age})")
    int insert(@Param("name") String name, @Param("age") Integer age);

    @Insert("INSERT INTO USER(NAME, AGE) VALUES(#{name,jdbcType=VARCHAR}, #{age,jdbcType=INTEGER})")
    int insertByMap(Map<String, Object> map);

    @Insert("INSERT INTO USER(NAME, AGE) VALUES(#{name}, #{age})")
    @Options(useGeneratedKeys = true, keyProperty = "id", keyColumn = "id")
    void insertByUser(User user);

    @Update("UPDATE user SET age=#{age}, name=#{name} WHERE id =#{id}")
    int update(User user);

    @Delete("DELETE FROM user WHERE id =#{id}")
    int delete(Long id);

    @Results({ @Result(property = "id", column = "id"), @Result(property = "name", column = "name"),
            @Result(property = "age", column = "age") })
    @Select("SELECT id,name, age FROM user")
    List<User> findAll();
}